<HTML>
<BODY>
<PRE>
<!-- Manpage converted by man2html 3.0.1 -->

<B><A HREF="TMPFILE.html">TMPFILE(3)</A></B>	       FreeBSD Library Functions Manual 	    <B><A HREF="TMPFILE.html">TMPFILE(3)</A></B>


</PRE>
<H2>NAME</H2><PRE>
     <B>tempnam</B>, <B>tmpfile</B>, <B>tmpnam</B> - temporary file routines


</PRE>
<H2>SYNOPSIS</H2><PRE>
     <B>#include</B> <B>&lt;stdio.h&gt;</B>

     <I>FILE</I> <I>*</I>
     <B>tmpfile</B>(<I>void</I>)

     <I>char</I> <I>*</I>
     <B>tmpnam</B>(<I>char</I> <I>*str</I>)

     <I>char</I> <I>*</I>
     <B>tempnam</B>(<I>const</I> <I>char</I> <I>*tmpdir</I>, <I>const</I> <I>char</I> <I>*prefix</I>)


</PRE>
<H2>DESCRIPTION</H2><PRE>
     The <B>tmpfile</B>() function returns a pointer to a stream associated with a
     file descriptor returned by the routine <B><A HREF="mktemp.html">mkstemp(3)</A></B>.  The created file is
     unlinked before <B>tmpfile</B>() returns, causing the file to be automatically
     deleted when the last reference to it is closed.  The file is opened with
     the access value `w+'.

     The <B>tmpnam</B>() function returns a pointer to a file name, in the P_tmpdir
     directory, which did not reference an existing file at some indeterminate
     point in the past.  P_tmpdir is defined in the include file &lt;<I>stdio.h</I>&gt;. If
     the argument <I>s</I> is non-NULL, the file name is copied to the buffer it ref-
     erences.  Otherwise, the file name is copied to a static buffer.  In ei-
     ther case, <B>tmpnam</B>() returns a pointer to the file name.

     The buffer referenced by <I>s</I> is expected to be at least L_tmpnam bytes in
     length.  L_tmpnam is defined in the include file &lt;<I>stdio.h</I>&gt;.

     The <B>tempnam</B>() function is similar to <B>tmpnam</B>(), but provides the ability
     to specify the directory which will contain the temporary file and the
     file name prefix.

     The environment variable TMPDIR (if set), the argument <I>tmpdir</I> (if non-
     NULL), the directory P_tmpdir, and the directory <I>/tmp</I> are tried, in the
     listed order, as directories in which to store the temporary file.

     The argument <I>prefix</I>, if non-NULL, is used to specify a file name prefix,
     which will be the first part of the created file name.  <B>Tempnam</B>() allo-
     cates memory in which to store the file name; the returned pointer may be
     used as a subsequent argument to <B><A HREF="malloc.html">free(3)</A></B>.


</PRE>
<H2>RETURN VALUES</H2><PRE>
     The <B>tmpfile</B>() function returns a pointer to an open file stream on suc-
     cess, and a NULL pointer on error.

     The <B>tmpnam</B>() and <B>tempfile</B>() functions return a pointer to a file name on
     success, and a NULL pointer on error.


</PRE>
<H2>ERRORS</H2><PRE>
     The <B>tmpfile</B>() function may fail and set the global variable <I>errno</I> for any
     of the errors specified for the library functions <B><A HREF="fopen.html">fdopen(3)</A></B> or
     <B><A HREF="mktemp.html">mkstemp(3)</A></B>.

     The <B>tmpnam</B>() function may fail and set <I>errno</I> for any of the errors speci-
     fied for the library function <B><A HREF="mktemp.html">mktemp(3)</A></B>.

     The <B>tempnam</B>() function may fail and set <I>errno</I> for any of the errors spec-
     ified for the library functions <B><A HREF="malloc.html">malloc(3)</A></B> or <B><A HREF="mktemp.html">mktemp(3)</A></B>.


</PRE>
<H2>SEE ALSO</H2><PRE>
     <B><A HREF="mktemp.html">mkstemp(3)</A></B>,  <B><A HREF="mktemp.html">mktemp(3)</A></B>


</PRE>
<H2>STANDARDS</H2><PRE>
     The <B>tmpfile</B>() and <B>tmpnam</B>() functions conform to ISO 9899: 1990 (``ISO
     C'').


</PRE>
<H2>BUGS</H2><PRE>
     These interfaces are provided for System V and ANSI compatibility only.
     The <B><A HREF="mktemp.html">mkstemp(3)</A></B> interface is strongly preferred.

     There are four important problems with these interfaces (as well as with
     the historic <B><A HREF="mktemp.html">mktemp(3)</A></B> interface).  First, there is an obvious race be-
     tween file name selection and file creation and deletion.	Second, most
     historic implementations provide only a limited number of possible tempo-
     rary file names (usually 26) before file names will start being recycled.
     Third, the System V implementations of these functions (and of <B><A HREF="mktemp.html">mktemp(3)</A></B>)
      use the <B><A HREF="access.html">access(2)</A></B> function to determine whether or not the temporary
     file may be created.  This has obvious ramifications for setuid or setgid
     programs, complicating the portable use of these interfaces in such pro-
     grams.  Finally, there is no specification of the permissions with which
     the temporary files are created.

     This implementation does not have these flaws, but portable software can-
     not depend on that.  In particular, the <B>tmpfile</B>() interface should not be
     used in software expected to be used on other systems if there is any
     possibility that the user does not wish the temporary file to be publicly
     readable and writable.

BSD			       November 17, 1993			     2
</PRE>
<HR>
<ADDRESS>
Man(1) output converted with
<a href="http://www.oac.uci.edu/indiv/ehood/man2html.html">man2html</a>
</ADDRESS>
</BODY>
</HTML>
